package com.maigao.util;

import java.time.LocalDate;
import java.time.LocalTime;

/**
 * @program: maigao
 * @description:
 * @author: yongza
 * @create: 2021-12-06 13:58
 **/
public class GoldUtils {

    /**
     * 上午9:00-11:30,下午13:30-15:00,下午21:00-次日2:30(夜盘)
     * 周六周日及法定假节日不开盘；
     * 周五晚上无夜盘
     * 法定节假日前一晚无夜盘
     *
     * @return
     */
    public static boolean canTrade() {
        if (HolidayUtils.isHoliday()) {
            return false;
        }
        LocalTime now = LocalTime.now();
        if (now.isAfter(LocalTime.of(9, 0)) && now.isBefore(LocalTime.of(11, 30))) {
            return true;
        }
        if (now.isAfter(LocalTime.of(13, 30)) && now.isBefore(LocalTime.of(15, 00))) {
            return true;
        }

        if (!HolidayUtils.isHoliday(LocalDate.now().plusDays(1))) {
            if (now.isAfter(LocalTime.of(21, 00)) || now.isBefore(LocalTime.of(2, 30))) {
                return true;
            }
        }
        return false;
    }
}
